<%@page import="java.util.ArrayList"%>
<%@page import="Board.BoardVo"%>
<%@page import="Board.BoardMyba"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script
	src="${pageContext.request.contextPath }/se2/js/HuskyEZCreator.js"
	type="text/javascript" charset="utf-8"></script>
<!-- 이미지 업로드 관련 js파일 -->
<script
	src="${pageContext.request.contextPath }/se2/photo_uploader/plugin/hp_SE2M_AttachQuickPhoto.js"
	type="text/javascript" charset="utf-8"></script>
<title>게시판 작성</title>
<script>
	function insert(frm) {
		
		var conte = document.getElementById("textAreaContent");
		var sHTML = oEditors.getById["textAreaContent"].getIR();//스마트 에디터에 있는 값 가져오기
		var chByte = 0;
		conte.value = sHTML;//스마트 에디터에 있는 값 textarea에 집어 넣기(from테그 값 넘길때 가져가기 위해서)
		var m = document.getElementById("text_title");
		var d = document.getElementById("text_title").value;
		//글자수 Byte체크
		/* for(var i = 0; i<d.length; i++){
			chByte += (d.charCodeAt(i) > 255) ? 2:1;
			
		}

		alert(chByte); */
		
		if (sHTML == "" || sHTML == "<br>") {
			alert("내용을 입력해주세요.");
			conte.focus();
			return false;
		}
		
		/*if(chByte <= 4){
			alert("내용을 입력해주세요.");
			return false;
		}*/
		if (m.value.trim() == "") {
			alert("제목을 입력해주세요.");
			m.focus();
			return false;
		}
		

		var f = confirm("등록하시겠습니까?");
		if (f) {
			/* alert(chByte); */
			frm.action = 'index.jsp?inc_content=./board/board_insert_result.jsp';
			frm.submit();
		} else {

		}
	}

	function init() {
		var resetkey = document.getElementsByTagName("body").item(0);
		resetkey.onkeydown = function(ev) {
			var key = ev.charCode || ev.keyCode || key.whitch;
			if (key == 116) {
				var s = confirm("창을 갱신하시겠습니까? 작업하던 데이터는 다시 돌아오지 않습니다.");
				if (s) {

				} else {
					return false;
				}
			}

		};

	}
	
	
</script>
<style>
/*전체 border*/
#main_div {
	width: 900px;
	margin: 0 auto;
	margin-top: 20px;
}

/*board을 구성하는 전체*/
#board_title,#board_title_text {
	display: inline-block;
}

/*#board_title {
	width: 50px;
	padding-top: 2px;
	padding-bottom: 2px;
	border-right: 1px dotted #dddddd;
	text-align: center;
	background-color: #c0ecff;
}*/
#select_box {
	width: 150px;
}

#board_title_text {
	width: 743px;
}

#board_con_title,#board_con_text,#board_master_radio {
	display: inline-block;
	margin-top: 5px;
}

#board_master_radio {
	font-size: 10pt;
}
/*내용표시*/
#board_con_title {
	width: 150px;
	text-align: center;
	background-color: #c0ecff;
}
/*여기에 SmartEditer을 적용시킴*/
#board_con_text {
	width: 900px;
}

/*SmartEditer 조절*/
#textAreaContent {
	min-width: 892px;
	max-width: 892px;
	min-height: 500px;
	max-height: 500px
}

/*제목창 조절*/
#text_title {
	min-width: 500px;
	max-width: 500px;
}
/**/
#file_title,#file_text {
	display: inline-block;
	margin-top: 5px;
}

/*#file_title {
	width: 80px;
	border-right: 1px dotted #dddddd;
	text-align: center;
	background-color: #c0ecff;
}*/

/*#file_text {
	width: 720px;
	
}*/
#file_box {
	border: 1px solid #dddddd;
	width: 898px;
	background-color: #ffffff;
}

/*버튼 담당*/
#button {
	margin-top: 10px;
	width: 900px;
	height: 40px;
	border: 1px dotted #dddddd;
	/*border-bottom :1px dotted #dddddd;*/
	background-color: #eeeeee;
	margin-bottom: 30px;
}

#submit,#list_button {
	margin-top: 8px;
	margin-right: 4px;
	border: 1px solid #7f7f7f;
	font-weight: bold;
	width: 50px;
	height: 25px;
}

#submit {
	background-color: #7f7f7f;
	color : white;
	cursor: pointer;
}

#list_button {
	background-color: #7f7f7f;
	color : white;
	cursor: pointer;
}


/*배너박스*/
 #banner_box {
	width: 900px;
	height: 50px;
	background-image : url(./board/images/write.jpg);
	margin-bottom: 10px;
}



</style>
</head>
<body>
	<jsp:useBean id="boardVo" class="Board.BoardVo" />
	<jsp:setProperty property="*" name="boardVo" />
	<%
		String app = (String) application.getAttribute("sa_no");

		//part저장
		String part2 = (String) session.getAttribute("part");

		String mid = (String) session.getAttribute("Mid");
		
		
		
		String pa = boardVo.getBo_part();
		
		/* out.print(part2);
		out.print(pa); */
		%>
	<script>
	window.onload = function(){
		var con = document.getElementById("select_box");
		<%if(mid.equals("1408M001")){%>
			<%if(pa.equals("공지사항")){%>
				con.options[0].selected = true;
			
			<%}else if(!pa.equals("공지사항")){%>
				con.options[0].selected = true;
			<%}%>
		<%}else{%>
			<%if(pa.equals("인사팀")){%>
			con.options[0].selected = true;
			<%}else if(pa.equals("개발팀")){%>
			con.options[1].selected = true;
			<%}else if(pa.equals("총무팀")){%>
			con.options[2].selected = true;
			<%}else if(pa.equals("홍보팀")){%>
			con.options[3].selected = true;
			<%}else if(pa.equals("건의사항")){%>
			con.options[4].selected = true;
			<%}else if(pa.equals("공지사항")){%>
			con.options[0].selected = true;
			
			<%}%>
		<%}%>
	}
	</script>
	
	<form method='post' enctype='multipart/form-data' action=''
		onsubmit="return insert(this)">
		<!-- onsubmit="return submit(this)" -->
		<div id='main_div'>
			<div id='banner_box'></div>
			<div id='board_title_div'>
				<div id='board_title'>
					<%
						if (mid.equals("1408M001")) {
					%>
					<select id='select_box' name='bo_part'>
						<option value="공지사항">공지사항</option>
					</select>
					<%
						} else {
					%>
					<select id='select_box' name='bo_part'>
						<option value="인사팀">인사팀</option>
						<option value="개발팀">개발팀</option>
						<option value="총무팀">총무팀</option>
						<option value="홍보팀">홍보팀</option>
						<option value="건의사항">건의사항</option>
					</select>
					<%
						}
					%>
				</div>
				<div id='board_title_text'>

					<input type='text' name='bo_title' id='text_title'
						placeholder='게시글을 작성해주세요.' value = '안녕하세요 신입사원 박현정입니다!'>

					<div id='board_master_radio'>
						<%
							if (mid.equals("1408M001")) {
						%>
						<input type="checkbox" id='board_radio' name='bo_checked'
							value="Y">중요공지로 올림(관리자모드)
						<%
							} else {
						%>

						<%
							}
						%>
					</div>
				</div>
			</div>

			<div id='file_div'>

				<div id=file_text>
					<input type="file" name='bo_file' id='file_box'>
				</div>
			</div>
			<div id='board_content'>
				<!--  <div id='board_con_title'>내 용</div>-->
				<div id='board_con_text'>
					<textarea name='bo_content' id='textAreaContent'></textarea>
				</div>
			</div>
			<div id='button' align="right">
				<input type='submit' value='등록' id='submit'> <input
					type='button' value='목록' id='list_button'
					onclick="history.back()">
			</div>
		</div>
	</form>
	<script>
		init();
	</script>
<script type="text/javascript">
		//스마트 에디터 붙이는 부분
		var oEditors = [];
		nhn.husky.EZCreator
				.createInIFrame({
					oAppRef : oEditors,
					elPlaceHolder : "textAreaContent",
					sSkinURI : "${pageContext.request.contextPath }/se2/SmartEditor2Skin.html",
					fCreator : "createSEditor2",
					htParams : {//등록 버튼 눌렀을때 페이지를 나가시겠습니까? 안뜨게 하는 작업
						fOnBeforeUnload : function() {
						}
					}
				});
		// textArea에 이미지 첨부
		function pasteHTML(filepath) {
			var sHTML = '<img src="${pageContext.request.contextPath }/se2/upload/'+filepath+'">';
			oEditors.getById["textAreaContent"].exec("PASTE_HTML", [ sHTML ]);

		}
	</script>
</body>
</html>